﻿@model WhatSales.Models.User
<html>
<head>
    <title>用户登录</title>
    <link href="/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/login.css" rel="stylesheet" type="text/css" />
    <script src="~/Scripts/jquery-3.6.0.min.js" type="text/javascript"></script>
    <script src="~/Scripts/bootstrap.min.js" type="text/javascript"></script>
</head>
<body>
    <div class="col-md-4 col-md-offset-4 login-banner">
        <div class="login-form">
            <form class="form-horizontal">
                <div class="form-group">
                    <h2 class="login-title">用户登录</h2>
                </div>
                <div class="form-group">
                    <div class="col-xs-2">
                        <span class="glyphicon glyphicon-user input-icon" aria-hidden="true"></span>
                    </div>
                    <div class="col-xs-10" style="padding-left:0;">
                        @Html.TextBoxFor(m => m.UserName, new { @class = "form-control input-name", @placeholder = "请输入用户名" })
                        @*@Html.ValidationMessageFor(m => m.UserName)*@
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
                        <span class="glyphicon glyphicon-lock input-icon" aria-hidden="true"></span>
                    </div>
                    <div class="col-xs-10 col-sm-10 col-md-10 col-lg-10" style="padding-left:0;">
                        @Html.PasswordFor(m => m.PassWord, new { @class = "form-control input-pwd", @placeholder = "请输入密码" })
                        @*@Html.ValidationMessageFor(m => m.PassWord)*@
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-12">
                        <div class="checkbox">
                            <label>
                                <input type="checkbox"> 记住密码
                            </label>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-12">
                        <button type="button" class="btn btn-primary login-button" onclick="login()">登录</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</body>
</html>

<script>
    function login() {
        $.post({
            url: "/User/Dologin",
            dataType: "json",
            data: {
                "username": $("#UserName").val(),
                "password": $("#PassWord").val()
            },
            success: function (data) {
                if (data.status == 500) {
                    alert(data.msg)
                    $("#UserName").val("");
                    $("#PassWord").val("");
                } else if (data.status == 200) {
                    alert(data.msg)
                    window.location="/Product/index"
                } else {
                    alert("未知错误")
                }
            }
        });
    }
</script>
